<?php


namespace App\Http\Controllers\Admin;


use App\Helpers\Api\ApiResponse;
use App\Helpers\Api\MiniProgramTrait;
use App\Http\Controllers\Controller;
use Dingo\Api\Routing\Helpers;

class BaseController extends Controller
{

    use Helpers, ApiResponse, MiniProgramTrait;

    public function __construct()
    {
//        header('Access-Control-Allow-Origin:*');
//        header('Access-Control-Allow-Methods:GET,POST,PUT,DELETE');
//        header('Access-Control-Allow-Headers:Origin, Content-Type, Cookie, Accept, X-CSRF-TOKEN');
//        header('Access-Control-Allow-Credentials:true');

    }

    /**
     * Get the token array structure.
     * @param $token
     * @return mixed
     */
    protected function respondWithToken($token)
    {
        return $this->success([
            'info' => $this->getUser(),
            'access_token' => $token,
            'token_type' => 'Bearer',
            'expires_in' => auth()->factory()->getTTL() * 60
        ]);
    }

    /**
     * @return User
     */
    protected function getUser()
    {
        return auth()->user();
    }

    function paginate($pagination, $extra = []) {
        $arr = [
            'list' => $pagination->items(),
            'total' => $pagination->total(),
            'has_more_page' => $pagination->hasMorePages(),
            'extra' => $extra
        ];
        return $this->success($arr);
    }

}

